package com.zmn.oms.common.enums;

import com.google.common.collect.Lists;
import com.zmn.common.utils.number.NumberUtil;
import com.zmn.oms.common.constant.OrderConsts;
import com.zmn.pay.common.constant.PayConsts;
import lombok.Getter;

import java.util.List;
import java.util.Objects;

/**
 * @ClassName RefundTypeEnum
 * @description: 退款方式枚举
 * @author: wangyanci
 * @create: 2021-06-29 18:37
 * @Version 1.0
 **/
@Getter
public enum RefundTypeEnum {

    ORIGINAL_REFUND(OrderConsts.ORDER_REFUND_TYPE_ONLINE, "原路退回"),

    ALIPAY_REFUND(PayConsts.PAY_CHANNEL_PLATFORM_ALIPAY, "支付宝"),

    WEIXIN_REFUND(PayConsts.PAY_CHANNEL_PLATFORM_WEIXINPAY, "微信"),

    BANK_REFUND(PayConsts.PAY_CHANNEL_PLATFORM_BANKTRANSFER, "银行转账"),

    CASH_REFUND(PayConsts.PAY_CHANNEL_PLATFORM_CASH, "现金退款"),
    ;


    private Integer type;

    private String desc;

    RefundTypeEnum(Integer type, String desc) {
        this.type = type;
        this.desc = desc;
    }

    private static List<RefundTypeEnum> refundTypeEnums = Lists.newArrayList(
            ALIPAY_REFUND,
            WEIXIN_REFUND,
            BANK_REFUND,
            CASH_REFUND
    );

    public static String getRefundTypeName(Integer refundType) {
        if (NumberUtil.isNullOrZero(refundType)) {
            return null;
        }

        for (RefundTypeEnum value : refundTypeEnums) {
            if (Objects.equals(value.getType(), refundType)) {
                return value.getDesc();
            }
        }
        return null;
    }

}
